<?php
Dream::run(); 
class Dream{
	public static function run(){
		self::setConst();
		self::createDir();
		self::loadCore();
		App::run();
	}	
	private static function loadCore(){
		$CoreArr = array(
			CORE_PATH . '/App.class.php',
			CORE_PATH . '/SmartyView.class.php',
			ORG_PATH . "/Smarty/Smarty.class.php",
			CORE_PATH . '/Controller.class.php',
			FUNCTION_PATH . '/functions.php',
		);
		foreach($CoreArr as $v){
			require_once $v;
		}
	}
	private static function createDir(){
		$dirArr = array(
			APP_CONFIG_PATH,
			APP_CONTROLLER_PATH,
			APP_VIEW_PATH,
			APP_PUBLIC_PATH,
			APP_INDEX_PATH,
			APP_CACHE_PATH,
			APP_COMPILE_PATH,
		);
		foreach ($dirArr as $v) {
			is_dir($v) || mkdir($v, 0777, TRUE);
		}
	}
	private static function setConst(){
		$path = str_replace('\\', '/', __FILE__);
		define('DREAM_PATH', dirname($path));
		define('ROOT_PATH', dirname(DREAM_PATH));
		define('CONFIG_PATH', DREAM_PATH . '/Config');
		define('DATA_PATH', DREAM_PATH . '/Data');
		define('FONT_PATH',DATA_PATH . '/Font');
		define('IMAGE_PATH', DATA_PATH . '/Image');
		define('EXTEND_PATH', DREAM_PATH . '/Extend');
		define('ORG_PATH', EXTEND_PATH . '/Org');
		define('LIB_PATH', DREAM_PATH . '/Lib');
		define('CORE_PATH', LIB_PATH . '/Core');
		define('FUNCTION_PATH', LIB_PATH . '/Function');
		define('TOOL_PATH', EXTEND_PATH . '/Tool');
		define('APP_PATH', ROOT_PATH . '/' .APP_NAME);
		define('APP_CONFIG_PATH', APP_PATH . '/Config');
		define('APP_CONTROLLER_PATH', APP_PATH . '/Controller');
		define('APP_VIEW_PATH', APP_PATH . '/View');
		define('APP_TEMP_PATH', APP_PATH . '/Temp');
		define('APP_CACHE_PATH', APP_TEMP_PATH . '/Cache');
		define('APP_COMPILE_PATH', APP_TEMP_PATH . '/Compile');
		define('APP_INDEX_PATH', APP_VIEW_PATH . '/Index');
		define('APP_PUBLIC_PATH', APP_VIEW_PATH . '/Public');
		define('IS_POST', $_SERVER['REQUEST_METHOD'] == 'POST' ? true : false);
	}
	
}	

?>